package com.cxhc.system.service.hcdoc.impl;

import com.cxhc.system.domain.hcdoc.HdBranchInfo;
import com.cxhc.system.domain.hcdoc.HdUserBranch;
import com.cxhc.system.mapper.hcdoc.HcDocUserMapper;
import com.cxhc.system.mapper.hcdoc.HdBranchInfoMapper;
import com.cxhc.system.mapper.hcdoc.HdUserBranchMapper;
import com.cxhc.system.service.hcdoc.HdBranchInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

import java.util.List;


/**
 * 用户 业务层处理
 *
 * @author Dhq
 */
@Service
public class HdBranchInfoServiceImpl implements HdBranchInfoService {

    @Autowired
    private HdBranchInfoMapper hdBranchInfoMapper;

    @Autowired
    private HdUserBranchMapper hdUserBranchMapper;

    @Autowired
    private HcDocUserMapper hcDocUserMapper;

    @Override
    public List<HdBranchInfo> selectList(HdBranchInfo hdUserInfo) {

        return hdBranchInfoMapper.selectList(hdUserInfo);
    }

    @Override
    public int batchInsert(List<HdUserBranch> hdUserBranches) {
        String userInfoId = hdUserBranches.get(0).getUserInfoId();
        hdUserBranchMapper.deleteByUserId(userInfoId);
        hdUserBranchMapper.batchInsert(hdUserBranches);
        return hcDocUserMapper.updateRoleName(Long.parseLong(userInfoId),"manager");
    }

    @Override
    public int delete(String userInfoId) {
        return hdUserBranchMapper.deleteByUserId(userInfoId);

    }

    @Override
    public List<HdBranchInfo> selectBranchByUser(String uerId) {
        return hdUserBranchMapper.selectBranchByUserId(uerId);
    }
}
